package com.appkubes.fintech.restful.application.file.controller;


import com.appkubes.fintech.common.response.Response;
import com.appkubes.fintech.restful.application.file.entity.IDCardVO;
import com.appkubes.fintech.restful.application.file.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;

@Slf4j
@Api(tags = "文件上传处理")
@RestController
@RequestMapping("file")
public class FileController {
    @Resource
    FileService fileService;

    @ApiOperation("上传身份证")
    @PostMapping("/uploadIDCard")
    public Response saveIdCardImage(@RequestParam("file") MultipartFile file,
                                    @Valid IDCardVO idCardVO,
                                    BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return Response.fail("参数检查失败");
        }

        Integer result = fileService.uploadIdCard(file, idCardVO);
        if (result == 0) {
            return Response.fail("文件上传失败");
        }
        return Response.success(result);
    }
}
